package models;

import java.util.Date;
import java.util.List;

import resulttypes.RouteRequestVO;
import siena.Generator;
import siena.Id;
import siena.Model;
import siena.Table;

import com.beoui.geocell.GeocellManager;
import com.beoui.geocell.model.LocationCapable;
import com.beoui.geocell.model.Point;

@Table("RouteRequest")
public class RouteRequest extends Model implements LocationCapable {
	@Id(Generator.AUTO_INCREMENT)
	public Long id;
	public Double fromLat;
	public Double fromLon;
	public Double toLat;
	public Double toLon;
	public Date time;
	public Integer party;
	public Double distance;
	public Long duration;
	public List<String> geocells;
//	public String keyString;

	public static RouteRequest fromVO(final RouteRequestVO vo) {
		final RouteRequest retReq = new RouteRequest();
		retReq.fromLat = vo.fromPoint[0];
		retReq.fromLon = vo.fromPoint[1];
		retReq.toLat = vo.toPoint[0];
		retReq.toLon = vo.toPoint[1];
		retReq.time = vo.time;
		retReq.party = vo.party;
		retReq.distance = vo.distance;
		retReq.duration = vo.duration;
		Point p = new Point(retReq.fromLat, retReq.fromLon);
		retReq.geocells = GeocellManager.generateGeoCell(p);
		return retReq;
	}

	public RouteRequestVO getRouteRequestVO() {
		return new RouteRequestVO();
	}
	
	public List<String> getGeocells() {
		return this.geocells;
	}
	
	public String getKeyString() {
		return this.id.toString();
	}

	
	public Point getLocation() {
		return new Point(fromLat,fromLon);
	}
}